package com.shuorikeji.huohuo.adapter;

import android.annotation.SuppressLint;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.bytedance.sdk.djx.model.DJXDrama;
import com.google.android.material.imageview.ShapeableImageView;
import com.shuorikeji.huohuo.R;
import com.shuorikeji.huohuo.bean.DjHisInfoBean;
import com.shuorikeji.huohuo.callback.ClickCallBack;
import com.shuorikeji.huohuo.common.Constant;
import com.shuorikeji.huohuo.utils.BusinessUtils;

import java.util.ArrayList;
import java.util.List;

import androidx.recyclerview.widget.RecyclerView;

public class DjReadHis1Adapter extends RecyclerView.Adapter<DjReadHis1Adapter.BaseViewHolder> {
    private final Context mContext;
    private List<DJXDrama> mData = new ArrayList<>();
    private ClickCallBack callBack;

    public DjReadHis1Adapter(Context context, ClickCallBack callBackFlag) {
        this.mContext = context;
        this.callBack = callBackFlag;
    }

    @Override
    public BaseViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(mContext).inflate(R.layout.dj_see_his_item_1_layout, parent, false);
        BaseViewHolder holder = new BaseViewHolder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(BaseViewHolder holder, @SuppressLint("RecyclerView") int position) {
        BusinessUtils.setLoadImg(mContext, mData.get(position).coverImage, holder.sivFm);
        holder.tvTitle.setText(mData.get(position).title);
        holder.tvInfo.setText(mData.get(position).desc);
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (callBack != null) {
                    callBack.onClick(1, mData.get(position));
                }
            }
        });
    }

    public void setData(List<DJXDrama> data) {
        if (mData != null) {
            mData.clear();
            mData.addAll(data);
            notifyDataSetChanged();
        }
    }

    @Override
    public int getItemCount() {
        return mData.size();
    }

    class BaseViewHolder extends RecyclerView.ViewHolder {
        ShapeableImageView sivFm;
        TextView tvState;
        TextView tvTitle;
        TextView tvInfo;

        public BaseViewHolder(View itemView) {
            super(itemView);
            sivFm = itemView.findViewById(R.id.siv_fm);
            tvState = itemView.findViewById(R.id.tv_state);
            tvTitle = itemView.findViewById(R.id.tv_title);
            tvInfo = itemView.findViewById(R.id.tv_info);
        }
    }
}
